package com.taoyuanx.api;

import com.taoyuanx.eum.ResultCode;

/**
 * @author 都市桃源
 *此处包装一层，允许用户自定义实现 消息码，消息配置，可以修改为国际化配置
 *从配置文件中加载消息msg
 */
public class ResultBuilder {

	    private Result result;
	    
	    public ResultBuilder(Result result) {
			this.result = result;
		}
	
		//简单结果生成
	    
		/**成功
		 * @param info
		 * @return
		 */
		public static Result buildOkResult(Object info){
			Result res = new Result();
			res.setInfo(info);
			res.setStatus(ResultCode.OK.code);
			return res;
		 }
		/**失败
		 * @param code
		 * @param msg
		 * @return
		 */
		public static Result buildFailResult(Integer code,String msg){
			Result res = new Result();
			res.setCode(code);
			res.setStatus(ResultCode.FAIL.code);
			res.setMsg(msg);
			return res;
		}
		
		//建造者模式，复杂结果生成
		public static ResultBuilder okBuilder(){
	    	return new ResultBuilder(new Result()).buildStatus(ResultCode.OK.code);
	    }
		public static ResultBuilder failBuilder(){
	    	return new ResultBuilder(new Result()).buildStatus(ResultCode.FAIL.code);
	    }
	    public ResultBuilder buildStatus(Integer status){
	    	this.result.setStatus(status);
	    	return this;
	    }
	    public ResultBuilder buildMsg(String msg){
	    	this.result.setMsg(msg);
	    	return this;
	    }
	    public ResultBuilder buildCode(Integer code){
	    	this.result.setCode(code);
	    	return this;
	    }
	    public ResultBuilder buildInfo(Object info){
	    	this.result.setInfo(info);
	    	return this;
	    }
	    public ResultBuilder buildExt(Object ext){
	    	this.result.setExt(ext);
	    	return this;
	    }
	    public Result build(){
	    	return this.result;
	    }
	   
}
